package com.sanyang.logistics.WarehouseManager.handler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sanyang.logistics.WarehouseManager.service.ReceiveService;
import com.sanyang.logistics.pojo.PickOut;
import com.sanyang.logistics.pojo.PickoutProdBridge;
import com.sanyang.logistics.pojo.PrepareInWarehouse;
import com.sanyang.logistics.pojo.PrepareOutWarehouse;
import com.sanyang.logistics.pojo.Product;
import com.sanyang.logistics.pojo.RcptDamage;
import com.sanyang.logistics.pojo.RcptProdBridge;
import com.sanyang.logistics.pojo.Receipt;
import com.sanyang.logistics.pojo.Warehouse;

@Controller
@RequestMapping("/shgl")
public class ReceiveHander {

	@Autowired
	private ReceiveService rService;
	
	@RequestMapping("/cx")
	@ResponseBody
	public Object cx(Receipt receipt){
		List<Receipt> all = rService.getAll(receipt);	
		for (Receipt receipt2 : all) {
			String status_id = receipt2.getStatus_id();
			if (status_id.equals("1")) {
				receipt2.setStatus_id("未完成");
			}else if(status_id.equals("2")){
				receipt2.setStatus_id("已完成");
			}
		}
		
		return all;
	}
	
	
	
	@RequestMapping("/so")
	@ResponseBody
	public Object so(){
	   List<Warehouse> querySome = rService.querySome();
//		System.out.println(querySome);
		return querySome;
	}
	

	@RequestMapping("/mxb")
	@ResponseBody
	public Object mxb(Integer rcpt_id){
		List<RcptProdBridge> getmxb = rService.getmxb(rcpt_id);
		System.out.println(getmxb+"++++++++++++++++++");
		return getmxb;
	}
	
	@RequestMapping("/hs")
	@ResponseBody
	public Object hs(Integer prod_id){
		System.out.println(prod_id);
		List<RcptProdBridge> geths= rService.geths(prod_id);
		System.out.println(geths+"-----------");
		return geths;
		
	}
	
	
	

	 @RequestMapping("/xgsj")
	 @ResponseBody
	  public Object xgsj(RcptProdBridge rcptProdBridge) {
		 System.out.println("asd:"+rcptProdBridge);
		 System.out.println(rcptProdBridge.getDestorycount1());
			rService.xgsj(rcptProdBridge);
		   return 5;
		}
	
	 @RequestMapping("/upSome")
	 @ResponseBody
	  public void upd(RcptDamage rcptDamage,Integer damageid) {
		 System.out.println(rcptDamage.getBar_code());
	
//		 rService.upd(rcptDamage);
		 rService.hsb(rcptDamage);

		 System.out.println(rcptDamage.getRcpt_id());
		    
		}
	 
	 @RequestMapping("/getDam")
	 @ResponseBody
	  public Object  getDam(RcptDamage rcptDamage) {
		 Integer prod_id = rcptDamage.getProd_id();
		 System.out.println("pro="+prod_id);
		 List<RcptDamage> dam = rService.getDam(prod_id);
		 System.out.println(dam);
		 return dam;
		}
	 
	
		@RequestMapping("/delhsb")
		@ResponseBody
		public void delhsb(Integer damageid) {
			System.out.println(damageid);
			rService.delhsb(damageid);
		}
		
		@RequestMapping("/mx")
		@ResponseBody
		public Object mx(Integer rcpt_id){
			List<RcptProdBridge> getmx = rService.getmxb(rcpt_id);
			System.out.println(getmx+"++++++++++++++++++");
			return getmx;
		}
		
		 @RequestMapping("/upda")
		 @ResponseBody
		  public void upda(RcptProdBridge rcptProdBridge,Integer rcpt_prod_id,Integer in_amt) {	 
				rService.upda(rcptProdBridge);
			    rService.del();
			    rService.tj(rcptProdBridge);
			}
	
		 
		 
		 
		@RequestMapping("/yrk")
		@ResponseBody
		public Object yckb(Integer rcpt_id) {
		 List<PrepareInWarehouse> getall = rService.getall(rcpt_id);
		 System.out.println(getall);
				for (PrepareInWarehouse prepareInWarehouse : getall) {
					for (PrepareInWarehouse prepareInWarehouses : getall) {
						String doneflag = prepareInWarehouse.getDone_flag();
						if (doneflag.equals("Y")) {
							prepareInWarehouses.setDone_flag("确认出库");
						}
						if (doneflag.equals("N")) {
							prepareInWarehouses.setDone_flag("未确认出库");
						}
					}
				}
				return getall;
		}
		 
		
		@RequestMapping("/dele")
		@ResponseBody
		public void dele(Integer preind,Integer lostcount,RcptProdBridge rcptProdBridge) {
			System.out.println(preind);
			rService.dele(preind);
			rService.upsl(rcptProdBridge);
           /* rService.upsl(pickoutProdBridge);*/
		}
		
		
		@RequestMapping("/updat")
		@ResponseBody
		public void updat(Integer rcpt_id) {
			rService.updat(rcpt_id);
			
		}
		
		
		@RequestMapping("/upzt")
		@ResponseBody
		public void upzt(Integer rcpt_id) {
			rService.upzt(rcpt_id);
		
			
		}
		 	/*
		 @RequestMapping("/sel")
			@ResponseBody
			public Object sel(Integer demageid){
				List<RcptDamage> sel = rService.sel(demageid);
				return sel;
				
			}*/
}
